package com.yang.mall.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yang.mall.dto.LiveShopCartDTO;
import com.yang.mall.dto.LiveShopCartNumDTO;
import com.yang.mall.entity.OLResponse;
import com.yang.mall.service.ILiveShopCartService;
import com.yang.mall.vo.LiveShopCartVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 购物车表 前端控制器
 * </p>
 *
 * @author kadorlin
 * @since 2022-10-25
 */
@Api(tags = "【小程序】购物车模块")
@RestController
@RequestMapping("/h5/liveShopCart")
public class LiveShopCartController {

    @Autowired
    private ILiveShopCartService liveShopCartService;


    @ApiOperation("购物车列表")
    @GetMapping("/list")
    public OLResponse<IPage<LiveShopCartVO>> list(LiveShopCartDTO liveShopCartDTO) {
        IPage<LiveShopCartVO> pageVO = liveShopCartService.list(liveShopCartDTO);
        return new OLResponse().success(pageVO);
    }


    @ApiOperation("添加到购物车")
    @PostMapping("/add")
    public OLResponse addItem(@RequestBody LiveShopCartDTO liveShopCartDTO) {
        liveShopCartService.addItem(liveShopCartDTO);
        return new OLResponse().success();
    }


    @ApiOperation("批量删除购物车")
    @DeleteMapping("/batchRemove")
    public OLResponse batchRemove(@RequestParam(name = "ids") List<Long> ids) {
        liveShopCartService.batchRemove(ids);
        return new OLResponse().success();
    }


    @ApiOperation("修改数量")
    @PutMapping("/edit")
    public OLResponse edit(@RequestBody LiveShopCartNumDTO liveShopCartNum) {
        liveShopCartService.edit(liveShopCartNum);
        return new OLResponse().success();
    }
}
